package com.calligraphy.product.web.rest;

import com.calligraphy.product.common.InventoryDTO;
import com.calligraphy.product.common.ProductInfoOutput;
import com.calligraphy.product.converter.ProductInfo2ProductInfoOutputConverter;
import com.calligraphy.product.model.ProductInfo;
import com.calligraphy.product.service.ProductService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.repository.query.Param;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author hy
 * @Date 2019/1/11 10:52
 **/
@Slf4j
@RestController
@RequestMapping("/provider")
public class ProviderController {

    @Autowired
    private ProductService productService;

    @PostMapping("/listForOrder")
    public List<ProductInfoOutput> listForOrder(@RequestBody List<String> productIdList) {
       log.error("商品列表={}",productService.findList(productIdList));
       return productService.findList(productIdList);
    }

    @PostMapping("/decreaseStock")
    public void decreaseStock(@RequestBody List<InventoryDTO> InventoryDTOList) {
        productService.decreaseStock(InventoryDTOList);
    }

    @PostMapping("/increaseStock")
    public void increaseStock(@RequestBody List<InventoryDTO> InventoryDTOList) {
        productService.increaseStock(InventoryDTOList);
    }

    @PostMapping("/findOne")
    public ProductInfoOutput findOne(String productId) {
        ProductInfo productInfo = productService.findOne(productId);
        return ProductInfo2ProductInfoOutputConverter.convert(productInfo);
    }

}
